/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * This script replaces default <tt>main.gsp</tt> generated by Grails application creator
 * with syntactically valid version.
 * Updated version features correct DOCTYPE declaration (XHTML 1.0 Strict),
 * text/html UTF-8 encoded content-type meta tag,
 * 2-spaces based indentation, correct EOF by appending EOL symbol.
 *
 * @author Vladimir Tsukur
 */

target("default": "replacing default 'main.gsp' generated by Grails application creator with syntactically valid version") {

    def typeList = ["xhtml-strict"]
    def type;

    def cliArgs = System.getProperty("grails.cli.args")

    if (!cliArgs) {
        type = typeList[0]
    }
    else {
        type = cliArgs.trim()
        if (!typeList.contains(type)) {
            echo("Invalid pattern type specified. Should be one of ${typeList}")
            return
        }
    }
    
    Ant.copy(file: "plugins/digr2id-scripts-0.1/grails-app/views/layouts/main_${type}.gsp",
            tofile: "grails-app/views/layouts/main.gsp", overwrite: true)

}
